using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

[RequireComponent(typeof(EventTrigger))]
public abstract class UButton : MonoBehaviour
{
	private void Awake()
	{
		this.AddEvent(EventTriggerType.PointerEnter, new UnityAction<BaseEventData>(this.OnPointerEnter));
		this.AddEvent(EventTriggerType.PointerDown, new UnityAction<BaseEventData>(this.OnPointerDown));
		this.AddEvent(EventTriggerType.PointerUp, new UnityAction<BaseEventData>(this.OnPointerUp));
		this.AddEvent(EventTriggerType.PointerExit, new UnityAction<BaseEventData>(this.OnPointerExit));
		this.Initialize();
	}

	private void Reset()
	{
		this.et = base.GetComponent<EventTrigger>();
	}

	private void AddEvent(EventTriggerType eventType, UnityAction<BaseEventData> callback)
	{
		EventTrigger.Entry entry = new EventTrigger.Entry();
		entry.eventID = eventType;
		entry.callback.AddListener(callback);
		this.et.triggers.Add(entry);
	}

	private void OnPointerEnter(BaseEventData data)
	{
		this.isIn = true;
		if (this.isDown)
		{
			this.OnHoverOver();
		}
	}

	private void OnPointerDown(BaseEventData data)
	{
		this.isDown = true;
		this.OnHoverOver();
	}

	private void OnPointerUp(BaseEventData data)
	{
		this.isDown = false;
		if (this.isIn)
		{
			this.OnHoverOut();
		}
	}

	private void OnPointerExit(BaseEventData data)
	{
		this.isIn = false;
		if (this.isDown)
		{
			this.OnHoverOut();
		}
	}

	protected virtual void Initialize()
	{
	}

	protected abstract void OnHoverOver();

	protected abstract void OnHoverOut();

	[SerializeField]
	[HideInInspector]
	private EventTrigger et;

	private bool isIn;

	private bool isDown;
}
